define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'exchange/log/index' + location.search,
                    add_url: 'exchange/log/add',
                   // edit_url: 'exchange/log/edit',
                    shareuser_url: 'share/user/index',//跳转到用户列表
                   // del_url: 'exchange/log/del',
                    multi_url: 'exchange/log/multi',
                    import_url: 'exchange/log/import',
                    table: 'exchange_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'code_id', title: __('Code_id')},
                        {field: 'code', title: __('Code'), operate: 'LIKE'},
                        {field: 'subgift_user_id', title: __('Subgift_user_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: '操作', table: table,
                            //events: Table.api.events.addtabs,
                            buttons: [
                                {
                                    name: 'shareuser',
                                    text: __('转赠用户'),
                                    // icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'share/user/index?user_id={subgift_user_id}',
                                    refresh: true,
                                    visible:function(row){
                                        if((1==1)){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }

                                },
                                {
                                    name: 'shareuser',
                                    text: __('用户'),
                                    // icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'share/user/index?user_id={user_id}',
                                    refresh: true,
                                    visible:function(row){
                                        if((1==1)){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }

                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
